package goodenglish.interfaces.studyword;

import goodenglish.domain.model.lexicon.Lexicon;
import goodenglish.domain.model.lexicon.StudyPlan;
import goodenglish.interfaces.Main;

import java.util.List;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;

public class SelectStudyPlanDlg extends BorderPane {
	ToggleGroup tg = new ToggleGroup();

	public SelectStudyPlanDlg(Lexicon lexicon) {
		this.getStyleClass().add("messageDialog");
		setMaxSize(500, 350);
		this.setTop(new Label("单词学习向导-选择学习计划"));

		VBox vBox = new VBox();

		List<StudyPlan> studyPlans = lexicon.getStudyPlans();
		for (StudyPlan studyPlan : studyPlans) {
			RadioButton studyPlanRB = new RadioButton(studyPlan.getName());
			studyPlanRB.setToggleGroup(tg);
			studyPlanRB.setUserData(studyPlan);
			vBox.getChildren().addAll(studyPlanRB);
		}

		this.setCenter(vBox);
		addBottom();

	}

	private void addBottom() {
		Button reviewBtn = new Button("完成");
		reviewBtn.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {
				StudyPlan studyPlan = (StudyPlan) tg.getSelectedToggle().getUserData();
				Main.instance.hideModalMessage();
				Main.root.setCenter(new StudyWordPane(studyPlan));

			}
		});
		this.setBottom(reviewBtn);
	}

}
